package com.example.back.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.back.service.RxService;
import com.example.common.support.Result;
import com.example.common.utils.RequestHelp;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @Author wxy
 * @Date 2021/1/13 14:40
 * @Version 1.0
 */
@RestController
@Api(tags = "处方订单")
@RequestMapping("/api/Rx")
public class RxController {
    @Resource
    private RxService rxService;

    @ApiOperation(value = "处方订单")
    @PostMapping(value = "/List")
    public Result<Map<String, Object>> List(HttpServletRequest request) {
        JSONObject Jo = RequestHelp.GetFromBodyJson(request);
        String rxorderno = Jo.getString("rxorderno");
        String orderno = Jo.getString("orderno");
        String dName = Jo.getString("dname");
        String pName = Jo.getString("pname"); // 药师
        String cName = Jo.getString("cname"); // 患者
        byte DType = Jo.getByteValue("dtype");
        int ChkStatus = Jo.getIntValue("chkstatus");

        int page = Jo.getIntValue("page");
        int limit = Jo.getIntValue("limit"); 
        return Result.success(rxService.List(rxorderno, orderno, dName, pName, cName, DType, ChkStatus, page, limit));
    }

    @ApiOperation(value = "订单导出")
    @PostMapping(value = "/OrderExportXls")
    public Result<Object> OrderExportXls(HttpServletRequest request) {
        JSONObject Jo = RequestHelp.GetFromBodyJson(request);
        String rxorderno = Jo.getString("rxorderno");
        String orderno = Jo.getString("orderno");
        String dName = Jo.getString("dname");
        String pName = Jo.getString("pname"); // 药师
        String cName = Jo.getString("cname"); // 患者
        byte DType = Jo.getByteValue("dtype");
        int ChkStatus = Jo.getIntValue("chkstatus");

        return Result.success(rxService.OrderExportXls(rxorderno, orderno, dName, pName, cName, DType, ChkStatus));
    }

    @ApiOperation(value = "处方列表", notes = "处方列表")
    @PostMapping(value = "/RxOrderList")
    public Result<Map<String, Object>> RxOrderList(HttpServletRequest request) {
        JSONObject Jo = RequestHelp.GetFromBodyJson(request);
        String rxorderno = Jo.getString("rxorderno");
        return Result.success(rxService.RxOrderList(rxorderno));
    }
}
